
// pages/user/work/work.js
const urls = require('../../../utils/url.js').urls;
const http = require('../../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: [], 
    zt:'',  
    zt1: '',  
    nc: '',
    tx: '',
  },
  userinfo:function(event){

    wx.navigateTo({
      url: '../../user/user_me/user_me',
    })
  },
   detail: function (event) {
     var index = event.currentTarget.dataset.index;
    
     wx.setStorageSync('gdid', this.data.items[index].id)
     wx.setStorageSync('gdzt', this.data.items[index].gd_state)
     console.log(wx.getStorageSync('gdid'))
    wx.navigateTo({
      url: '../../user/work_detail/work_detail',
    })
  },
  bt_qx: function (event) {
    var that = this;
    var index = event.currentTarget.dataset.index;
    wx.setStorageSync('gdid', this.data.items[index].id)
    wx.setStorageSync('gdzt', this.data.items[index].gd_state)
    var param ={
      id: wx.getStorageSync('gdid')
    }
    http(urls.qxgd, param,function(res){
      console.log(res)
        
        if(res.code==0){
          wx.showToast({
            title: res.msg,
          })
          if (getCurrentPages().length != 0) {
            //刷新当前页面的数据
            getCurrentPages()[getCurrentPages().length - 1].onLoad()
          }
        }
    
    })

  },
  bt_pj: function (event) {
    var index = event.currentTarget.dataset.index;
    wx.setStorageSync('gdid', this.data.items[index].id)
    wx.setStorageSync('gdzt', this.data.items[index].gd_state)
  
    console.log(wx.getStorageSync('gdid'))
    wx.navigateTo({
      url: '../../user/evaluate/evaluate',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showNavigationBarLoading();
    var param = {
      openid: app.globalData.openid                                           //openId

    };
    http(urls.details, param, function (res) {
      console.log(res)
      that.setData({
        nc: res.data.nickname,
        tx: res.data.avatarurl,
      })
      wx.hideNavigationBarLoading();
    })

    http(urls.gdck, param, function (res){
      console.log(res)
      that.setData({
        items:res.data
      })
      wx.hideNavigationBarLoading();
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (getCurrentPages().length != 0) {
      //刷新当前页面的数据
      getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
   
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})